<template>
	<div class="topnav">
		<a class="city" @click="path">
			<span v-if="cityinfo.city!=null">{{cityinfo.city}}</span>
			<span v-else>广州</span>
			<i></i>
		</a>
		<div class="nav-select">
			<router-link to="/"><span class="nav-text">热映</span></router-link>
			<router-link to="/released"><span class="nav-text">待映</span></router-link>
			<router-link to="/classic"><span class="nav-text">经典电影</span></router-link>
		</div>
		<router-link to="/search" class="search"></router-link>
	</div>

	<!-- <router-view></router-view> -->

</template>

<script>
	export default {
		props: {
			lat: [Number, String],
			lng: [Number, String]
		},
		data() {
			return {
				cityinfo: {
					city: null,
					id: null
				}
			}
		},
		created() {
			this.getCity()
		},
		methods: {
			async getCity() {
				let re = await this.$axios.get(
					`https://apis.netstart.cn/maoyan/city/latlng?lat=${this.lat}&lng=${this.lng}`)
				console.log(re)
				this.cityinfo.city = re.city;
				this.cityinfo.id = re.id;
				console.log(this.cityinfo)
			},
			path() {
				this.$router.push({
					path: "/city",
					query: {
						cityinfo: this.cityinfo
					}
				})
			},

		},
		components: {},
	}
</script>

<style lang="less" scoped>
	.topnav {
		width: 100%;
		height: 44px;
		// border-bottom: 2px solid #e6e6e6;
		display: flex;
		align-items: center;
		justify-content: space-between;
		z-index: 5;
		position: fixed;
		top: 50px;
		left: 0px;
		background: #fff;

		.city {
			padding-left: 15px;
			height: 44px;
			line-height: 44px;

			&>span {
				color: #666;
				font-size: 15px;
			}

			&>i {
				width: 0;
				height: 0;
				border: 4px solid transparent;
				border-top-color: #b0b0b0;
				display: inline-block;
				margin-left: 8px;
				margin-right: 10px;
				margin-top: 10px;
			}
		}

		.nav-select {
			display: flex;
			height: 44px;
			line-height: 44px;
			justify-content: space-around;
			font-size: 15px;
			font-weight: 500;
			z-index: 5;
			height: 44px;
			flex: 1;

			&>a {
				display: block;
				color: #666;
				padding: 0px 5px;
				box-sizing: border-box;
				width: 50px;
				height: 44px;
				line-height: 44px;
				position: relative;
				text-align: center;
				flex: 1;

				.nav-text {
					font-size: 15px;
					font-weight: 700;
				}

				&:nth-child(4) {
					width: 85px;
				}

				&.router-link-exact-active {
					box-sizing: border-box;

					.nav-text {
						font-size: 18px;
						color: black;
					}

					&::after {
						content: "";
						position: absolute;
						left: 50%;
						bottom: -1px;
						z-index: 3;
						width: 20px;
						height: 3px;
						border-radius: 0.02rem;
						transform: scaleY(0.5);
						background: #dd001b;
						transform: translateX(-50%);
					}
				}

				&>span {
					display: inline-block;
				}
			}
		}

		.search {
			padding: 10px 15px 10px 10px;
			width: 20px;
			height: 20px;
			background: url("../assets/img/search.png") no-repeat;
			background-size: 20px;
			background-position: 15px;
		}
	}
</style>
